# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 下午1:36
# @Author  : wb
# @Email   : wb@163.com
# @File    : task_add_page.py
# @Software: PyCharm

from time import sleep
from pages.wb_base_page import BasePage
from selenium.webdriver.common.by import By


class TaskAddPage(BasePage):
    url = '/crm'
    # 定位器
    '''获取主题输入框元素'''
    subject_locator = (By.NAME, 'subject')
    '''获取负责人元素'''
    owner_locator = (By.ID, 'owner_name')
    '''获取勾选框元素'''
    choose_locator = (By.CSS_SELECTOR, '#ta1 > span:nth-child(4) > input')
    '''获取确定按钮元素'''
    accept_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')
    '''获取描述输入框元素'''
    descript_locator = (By.CSS_SELECTOR, 'body')
    '''获取保存按钮元素'''
    save_btn_locator = (By.CSS_SELECTOR,'body > div.container > div.row-fluid > div > form > table > thead > tr > td:nth-child(2) > input:nth-child(1)')

    # 浏览器操作
    def add_input_subject(self,subject):
        '''主题框输入1字符'''
        self.driver.find_element(*self.subject_locator).send_keys(subject)
    def click_owner(self):
        '''点击负责人选择框'''
        self.driver.find_element(*self.owner_locator).click()
        sleep(1)
    def click_choose(self):
        '''勾选负责人'''
        self.driver.find_element(*self.choose_locator).click()
    def click_accept(self):
        '''点击确定'''
        self.driver.find_element(*self.accept_locator).click()
        sleep(1)
    def switch_frame(self):
        '''切换frame'''
        self.driver.switch_to.frame(self.driver.find_element(By.CSS_SELECTOR,'body > div.container > div.row-fluid > div > form > table > tbody > tr:nth-child(7) > td:nth-child(2) > div > div.ke-edit > iframe'))
        sleep(1)
    def add_input_descript(self,descript):
        '''描述框输入1字符'''
        self.driver.find_element(*self.descript_locator).send_keys(descript)
    def switch_home_frame(self):
        '''切换frame到主文档'''
        self.driver.switch_to.default_content()
        sleep(1)
    def click_save(self):
        '''点击保存'''
        self.driver.find_element(*self.save_btn_locator).click()
        sleep(3)
